<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/notes.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Kevin's Homepage</title>
<!-- InstanceEndEditable -->
<link href="../main.css" rel="Stylesheet">



<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>

<div id="container">

		<div id="imagehi"><img id="hi" src="../images/hi.gif" alt="picture hi" /></div>
	
  		<div id="rightcolumn">
		<div id="title">
			<h1 id="titletext">Kevin's Home</h1>
		</div>
		
		<ol id="navlinks">
			<li><a href="../index.html">Home</a></li>
			<li><a href="../aboutmyself.html">About Myself</a></li>
			<li><a href="../photoalbum/photoalbum.html">Photo Album</a></li>
			<li><a href="notes.html">Quick Notes</a></li>
			<li class="last"><a href="../links.html">Links</a></li>
		</ol>
		
	    
	<div id="leftbar">  
		<ol>
			<li><a href="c.html">C &amp; C++</a></li>
			<li><a href="java.html">Java</a></li>
			<li><a href="perl.html">Perl</a></li>
			<li><a href="centos.html">Centos</a></li>
			<li><a href="unix.html">Unix</a></li>
			<li><a href="css.html">CSS</a></li>
			<li><a href="php.html">PHP</a></li>
			<li><a href="sql.html">SQL</a></li>
			<li><a href="photoshop.html">Photoshop</a></li>
			<li><a href="windows.html">Windows</a></li>
			<li><a href="numbers.html">Numbers</a></li>
			<li><a href="misc.html">Misc</a></li>
		</ol>
	</div><!-- end of leftbar -->
	    <!-- InstanceBeginEditable name="EditRegion_submain" -->
	    <div id="main">
  <h3>Perl (Practical Extraction &amp; Reporting Language) </h3>
  <h4>Install perl module using CPAN shell with root account</h4>
  <pre class="codeblock">perl -MCPAN -e shell
for first time user, /root/.cpan/* directory is created
configuration file is at /usr/lib/perl5/5.6.1/CPAN/Config.pm config.pm~
remove these two files, run above command will re-initialise perl module setup
CPAN>install SOAP::Lite
CPAN>install Bundle::Apache
CPAN>install Bundle::BioPerl
module is installed at /usr/lib/perl5/site_perl/5.6.1/*</pre>
  
  <h4>Call unix shell inside perl script</h4>
  	
	  <pre class="codeblock">#!/usr/local/bin/perl
$cmd="mkdir hello";
if (system($cmd)) {
	print "mkdir failed\n";
}
$output = `checkdb -o a7063c`; #back tick, not single quote, collect output into string
@output = `checkdb -o a7063c`; # collect output into array 
$output = system ("checkdb -o a7063c"); # get exist status cod</pre>
 
  <h4>Read and wtite file</h4>
	<pre class="codeblock">open (IN, "seq1.txt");
@lines=<IN>;
close (IN);

open(IN, "seq1.txt");
while(<IN>){
$tmp .=$_; 
}
close (IN);

open(OUT, "> out.txt");
print OUT $tmp;
close (OUT);

# there is a space between each array element 
print ("\@lines:\n@lines\n");</pre>

	<h4>Array</h4>
	<pre class="codeblock">@array=("hello", 283, "Three", 16.439);
print "$array[0]";

@array = qw (element seperate by spce);

@array = ('a' .. 'z');
print "\n@array\n"; # result is: a b c d e f g h... z</pre>

	<h4>Hash table</h4>
	<pre class="codeblock">%hash = (width => '300',
height => '150');
print "$hash{'width'}";
$hash{'color'} = 'blue';
print %hash, "\n"; 

@keys = keys(%hash);
delete ($hash{'color'});</pre>

	<h4>Reference</h4>
	<pre class="codeblock">use strict;
use warnings;
my $variable = 10;
my $reference = \$variable;
print "$reference, $$reference"; # SCALAR(0x8a31018)?10

my @array = qw (duck pig horse);
my %hash = ( duck => "quack",
pig => "oink"); 
my $arrayreference = \@array;
my $hashreference = \%hash;
print "$$arrayreference[1]", "$$hashreference{duck}";
print "$arrayreference->[1], "$hashreference->{duck}";
print "$hashreference->{'duck'}";</pre>

	<h4>Use your own perl modules</h4>
	<pre class="codeblock">#!/bin/perl
use lib "/home/a7063c/perllib";</pre>

	<h4>If possible, don't use "for" loop in perl</h4>
        </div>
    <!-- InstanceEndEditable --></div><!-- end of rightcolumn div -->
</div><!-- end of container div -->

<div id="footer">
	<p>Website design by <a href="../index.html">Kevin Mu Qing</a>; Hosting by <a href="http://www.jimlei.com" target="_blank">Jim Xianyu Lei</a></p>
</div>

</body>
<!-- InstanceEnd --></html>
